<?php

namespace App\Http\Controllers\Admin;

use App\Exports\AnalyseExport;
use App\Exports\OrderExport;
use App\Exports\UsersExport;
use App\Http\Controllers\BaseController;
use App\Http\Controllers\Controller;
use App\Models\Products;
use App\Models\User;
use App\Models\Users;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
class PrintExcelController extends BaseController
{
    /**
     * 訂單導出
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function export(Request $request)
    {
    //   dd($request->all());
    // return $this->success(asset('storage/app/public/excel_name.xlsx')
// );

    $fileName = date('YmdHis') . '.xlsx';
       $data=Users::get()->toArray();
        Excel::store(new UsersExport($data), 'public/excel/' . $fileName);
        return $this->success($fileName);

    }

    /**
     * 商品數據分析打印
     * @param Request $request
     */
    public function exportProduct(Request $request)
    {
        $fileName = date('YmdHis') . '.xlsx';
        $data=Products::select('name','price','sale_num','browse','num','sale')->get()->toArray();
        Excel::store(new AnalyseExport($data), 'public/excel/' . $fileName);
        return $this->success($fileName);
    }
}
